func maxProfit(prices []int) int {
    /*
        1. dp[i][0] 第i天持有股票所得最多现金值
           dp[i][1] 第i天不持有股票所得最多现金值

        2. dp[i][0] = max(dp[i-1][0], -prices[i])
           dp[i][1] = max(dp[i-1][1], dp[i-1][0] + price[i])

        3. 初始化
           dp[0][0] = -price[0]
           dp[0][1] = 0
    */

    dp := make([][2]int, len(prices))
    dp[0][0] = -prices[0]
    dp[0][1] = 0
    for i:=1; i<len(prices); i++ {
        dp[i%2][0] = max(dp[(i-1)%2][0], -prices[i])
        dp[i%2][1] = max(dp[(i-1)%2][1], dp[(i-1)%2][0] + prices[i])
    }
    return dp[(len(prices)-1)%2][1]
}

func max(a, b int) int {
    if a > b {
        return a
    }
    return b
}
